﻿using ConfExpert.Forms.Base;
using ConfExpert.Utility;
using DevTeam;

using System;
namespace ConfExpert.Forms.Depo._7C
{
    public partial class DonmesiBeklenen : XForm
    {
        int CKBatchId;
        public DonmesiBeklenen(int CKBatchId)
        {
            InitializeComponent();
            this.CKBatchId = CKBatchId;
            this.Text += "- " + AppSession.Lookups.CKBatch.FindByCKBatchId(CKBatchId).Notes;
        }

        private void DonmesiBeklenen_Load(object sender, EventArgs e)
        {

            barEditItem1.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
            //barEditItem1.EditValueChanged += barEditItem1_EditValueChanged;
            //splitContainerControl1.SizeChanged += MySizeChanged;
            xtraTabControl1.SelectedTabPage = xtraTabPage2;
            Rfrsh();

        }

        void barEditItem1_EditValueChanged(object sender, EventArgs e)
        {
            Rfrsh();
        }

        private void Rfrsh()
        {
            gridView1.Init("GetDonusAnaliz", CKBatchId);
            gridView1.AddDetailGrid(gridView2, "CikisPartisiId,ProductId");
            gridView3.Init(gridView1.Dataset().Tables[2].Copy());

            gridView1.SetCaptions("CikisPartisiId:CPId");
            gridView1.FormatAsNumber(1, "CikanMetraj", "DonenMetraj");
            gridView1.FormatAsPercentage("DonenYuzde");
            gridView1.AddSummary("CikanMetraj", "DonenMetraj");

            gridView2.FormatAsNumber(1, "QtyAx", "QtyGx");
            gridView2.AddSummary("QtyGx", "QtyGx");
            gridView2.DoubleClick -= gridView2_DoubleClick;
            gridView2.DoubleClick += gridView2_DoubleClick;

            gridView3.FormatAsDate("CikisTarihi");
            gridView3.FormatAsNumber(1, "EskiQty", "YeniQty");
            gridView3.AddSummary("EskiQty", "YeniQty");

            gridView1.MakeReadOnly();
            gridView2.MakeReadOnly();
            gridView3.MakeReadOnly();

            gridView1.MakeRowSelectable();

            gridView1.BestFitColumns();
            gridView2.BestFitColumns();
            gridView3.BestFitColumns();
        }

        void gridView2_DoubleClick(object sender, EventArgs e)
        {
            string Modello = gridView2.GetFocusedRowCellDisplayText("Modello");
            int CikisPartisiId = gridView1.GetFocusedRowCellDisplayText("CikisPartisiId").ToInt();
            using (DonmesiBeklenenBM bm = new DonmesiBeklenenBM(Modello, CikisPartisiId))
                bm.ShowDialog();
        }


    }
}
